//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <mantle.h>

// member functions
//
UInt32 CModule::AddRef(void)
{
    return m_cRef.Increment();
}

UInt32 CModule::Release(void)
{
    Int32 lRef = m_cRef.Decrement();

    assert(lRef >= 0);

    if (0 == lRef) {
        GUnloadModule(this);
        delete this;
    }
    return (UInt32)lRef;
}

CModule::~CModule()
{
    ModuleRef * pModRef;

    pModRef = (ModuleRef *)m_rModuleList.m_pNext;
    while ((DLinkNode *)pModRef != &m_rModuleList) {
        pModRef->Detach();
        pModRef->m_pModule->Release();
        delete pModRef;
        pModRef = (ModuleRef *)m_rModuleList.m_pNext;
    }
}
